package com.applications.codemash.core;

import java.util.ArrayList;
import java.util.List;

import com.applications.codemash.utility.parser.SpeakerFeedParser;

public class SpeakerCollection extends ArrayList<Speaker>
{
	private static final long serialVersionUID = 453750850021769527L;
	
	private SpeakerCollection()
	{
		
	}
	
	public static SpeakerCollection GetAllSpeakers()
	{
		SpeakerFeedParser parser = new SpeakerFeedParser(Constants.GetAllSpeakersUri());
		List<Speaker> speakerList = parser.parse();
		SpeakerCollection collection = new SpeakerCollection();
		
		for (int i=0; i<speakerList.size(); i++)
		{
			collection.add(speakerList.get(i));
		}
		
		return collection;
	}
	
	public Speaker getSpeakerByUri(String uri)
	{
		for (Speaker speaker : this)
		{
			if (speaker.getSpeakerUri().compareToIgnoreCase(uri) == 0)
			{
				return speaker;
			}	
		}
		
		// load the speaker from the URI if possible
		return null;
	}
}
